﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Calendar;
using Google.GData.Client;
using Google.GData.Extensions;
using sp2google.common;
using sp2google.common.Entities.Calendar;
using sp2google.common.Interfaces;

namespace s2google.sync.SyncProviders
{
    public class GoogleProvider : ISyncProvider<CalendarItem>
    {
        private CalendarService _svc;
        private Uri _url;

        public void Init(Configuration config)
        {
            _svc = new CalendarService("sp2google");

            //can use the token instead of the credentials here
            _svc.Credentials = new GDataCredentials(config.GoogleUserName, config.GooglePassword);

            _url = new Uri("https://www.google.com/calendar/feeds/default/private/full");
        }

        public void Add(CalendarItem item)
        {
            var entry = new EventEntry();

            entry.Title.Text = item.Title;
            entry.Content.Content = item.Description;

            var time = new When(item.Start, item.End);
            entry.Times.Add(time);

            _svc.Insert(_url, entry);
        }

        public void Delete(CalendarItem item)
        {
            throw new NotImplementedException();
        }

        public List<CalendarItem> GetCollection()
        {
            throw new NotImplementedException();
        }

        public bool Exists(CalendarItem item)
        {
            return false;
        }

        public void Dispose()
        {
            //clean up resources
        }
    }
}
